]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
scroll-view-fade: Put the shader in another file
authorJasper St. Pierre <jstpierre@mecheye.net>
Wed, 28 Nov 2012 21:07:25 +0000 (16:07 -0500)
committerJasper St. Pierre <jstpierre@mecheye.net>
Thu, 29 Nov 2012 21:17:09 +0000 (16:17 -0500)
This doesn't make any changes to the shader outside of adding
a header; it simply makes changes in the future easier to edit.

https://bugzilla.gnome.org/show_bug.cgi?id=689249

.gitignore
src/Makefile-st.am
src/data-to-c.pl [new file with mode: 0755]
src/st/st-scroll-view-fade.c
src/st/st-scroll-view-fade.glsl [new file with mode: 0644]

index 9eb9209fc479c3e1959c198e2de364dd7ab94cb1..eee501adc8dd3a00c9826b407cff398d3ddc052e 100644 (file)
@@ -85,6 +85,8 @@ src/test-theme
 src/st.h
 src/stamp-st.h
 src/stamp-st.h.tmp
+src/st-scroll-view-fade-generated.c
+src/stamp-st-scroll-view-fade-generated.c
 stamp-h1
 tests/run-test.sh
 xmldocs.make
index 0ae490a6f91ff274a8e6c8719fa70592df9d8536..cb96024834c19740f6915adeee36b36a48479253 100644 (file)
@@ -87,6 +87,20 @@ stamp-st.h: Makefile
 BUILT_SOURCES += st.h
 CLEANFILES += stamp-st.h
 
+st-scroll-view-fade-generated.c: stamp-st-scroll-view-fade-generated.c
+       @true
+stamp-st-scroll-view-fade-generated.c: $(srcdir)/st/st-scroll-view-fade.glsl $(srcdir)/data-to-c.pl
+       $(AM_V_GEN) $(srcdir)/data-to-c.pl $(srcdir)/st/st-scroll-view-fade.glsl st_scroll_view_fade_glsl > $@.tmp && \
+       (cmp -s $@.tmp st-scroll-view-fade-generated.c || cp $@.tmp st-scroll-view-fade-generated.c) && \
+       rm -f $@.tmp &&                         \
+       echo timestamp > $(@F)
+
+BUILT_SOURCES += st-scroll-view-fade-generated.c
+EXTRA_DIST +=                                  \
+       st/st-scroll-view-fade.glsl             \
+       data-to-c.pl                            \
+       $(NULL)
+
 st_source_private_h =                          \
        st/st-private.h                         \
        st/st-table-private.h                   \
diff --git a/src/data-to-c.pl b/src/data-to-c.pl
new file mode 100755 (executable)
index 0000000..20ba2fb
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# Copyright © 2011 Red Hat, Inc
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the licence, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# Author: Kalev Lember <kalevlember@gmail.com>
+
+
+if (@ARGV != 2) {
+    die "Usage: data-to-c.pl <filename> <variable>\n";
+}
+
+$file = $ARGV[0];
+
+open (FILE, $file) || die "Cannot open $file: $!\n";
+
+printf ("const char %s[] = \"", $ARGV[1]);
+while (my $line = <FILE>) {
+    foreach my $c (split //, $line) {
+        printf ("\\x%02x", ord ($c));
+    }
+}
+print "\";\n";
+
+close (FILE);
index 36d36407068cb0aa061a675d4873d85bdb1a491c..5093e7d191fa5a306fa11c8add1867ae1fd53c15 100644 (file)
@@ -37,61 +37,7 @@ typedef struct _StScrollViewFadeClass  StScrollViewFadeClass;
 
 #define DEFAULT_FADE_OFFSET 68.0f
 
-static const gchar *fade_glsl_shader =
-"uniform sampler2D tex;\n"
-"uniform float height;\n"
-"uniform float width;\n"
-"uniform float offset_bottom;\n"
-"uniform float offset_top;\n"
-"uniform float offset_right;\n"
-"uniform float offset_left;\n"
-/*
- * Used to pass the fade area to the shader
- *
- * [0][0] = x1
- * [0][1] = y1
- * [1][0] = x2
- * [1][1] = y2
- *
- */
-"uniform mat2 fade_area;\n"
-"\n"
-"void main ()\n"
-"{\n"
-" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n"
-" float y = height * cogl_tex_coord_in[0].y;\n"
-" float x = width * cogl_tex_coord_in[0].x;\n"
-" float ratio = 1.0;\n"
-" float fade_bottom_start = fade_area[1][1] - offset_bottom;\n"
-" float fade_right_start = fade_area[1][0] - offset_right;\n"
-" float ratio_top = y / offset_top;\n"
-" float ratio_bottom = (fade_area[1][1] - y)/(fade_area[1][1] - fade_bottom_start);\n"
-" float ratio_left = x / offset_left;\n"
-" float ratio_right = (fade_area[1][0] - x)/(fade_area[1][0] - fade_right_start);\n"
-" bool in_scroll_area = fade_area[0][0] <= x && fade_area[1][0] >= x;\n"
-" bool fade_top = y < offset_top && in_scroll_area && (y >= fade_area[0][1]);\n"
-" bool fade_bottom = y > fade_bottom_start && in_scroll_area && (y <= fade_area[1][1]);\n"
-" bool fade_left = x < offset_left && in_scroll_area && (x >= fade_area[0][0]);\n"
-" bool fade_right = x > fade_right_start && in_scroll_area && (x <= fade_area[1][0]);\n"
-"\n"
-" if (fade_top) {\n"
-"  ratio *= ratio_top;\n"
-" }\n"
-"\n"
-" if (fade_bottom) {\n"
-"  ratio *= ratio_bottom;\n"
-" }\n"
-"\n"
-" if (fade_left) {\n"
-"  ratio *= ratio_left;\n"
-" }\n"
-"\n"
-" if (fade_right) {\n"
-"  ratio *= ratio_right;\n"
-" }\n"
-"\n"
-"  cogl_color_out = color * ratio;\n"
-"}";
+#include "st-scroll-view-fade-generated.c"
 
 struct _StScrollViewFade
 {
@@ -549,7 +495,7 @@ st_scroll_view_fade_init (StScrollViewFade *self)
       if (clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL))
         {
           shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT);
-          cogl_shader_source (shader, fade_glsl_shader);
+          cogl_shader_source (shader, (const char *) st_scroll_view_fade_glsl);
           cogl_shader_compile (shader);
           if (!cogl_shader_is_compiled (shader))
             {
diff --git a/src/st/st-scroll-view-fade.glsl b/src/st/st-scroll-view-fade.glsl
new file mode 100644 (file)
index 0000000..2e40420
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * st-scroll-view-fade.glsl: Edge fade effect for StScrollView
+ *
+ * Copyright 2010 Intel Corporation.
+ * Copyright 2011 Adel Gadllah
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+uniform sampler2D tex;
+uniform float height;
+uniform float width;
+uniform float offset_bottom;
+uniform float offset_top;
+uniform float offset_right;
+uniform float offset_left;
+
+/*
+ * Used to pass the fade area to the shader
+ *
+ * [0][0] = x1
+ * [0][1] = y1
+ * [1][0] = x2
+ * [1][1] = y2
+ *
+ */
+uniform mat2 fade_area;
+
+void main ()
+{
+    vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));
+    float y = height * cogl_tex_coord_in[0].y;
+    float x = width * cogl_tex_coord_in[0].x;
+    float ratio = 1.0;
+    float fade_bottom_start = fade_area[1][1] - offset_bottom;
+    float fade_right_start = fade_area[1][0] - offset_right;
+    float ratio_top = y / offset_top;
+    float ratio_bottom = (fade_area[1][1] - y)/(fade_area[1][1] - fade_bottom_start);
+    float ratio_left = x / offset_left;
+    float ratio_right = (fade_area[1][0] - x)/(fade_area[1][0] - fade_right_start);
+    bool in_scroll_area = fade_area[0][0] <= x && fade_area[1][0] >= x;
+    bool fade_top = y < offset_top && in_scroll_area && (y >= fade_area[0][1]);
+    bool fade_bottom = y > fade_bottom_start && in_scroll_area && (y <= fade_area[1][1]);
+    bool fade_left = x < offset_left && in_scroll_area && (x >= fade_area[0][0]);
+    bool fade_right = x > fade_right_start && in_scroll_area && (x <= fade_area[1][0]);
+
+    if (fade_top) {
+        ratio *= ratio_top;
+    }
+
+    if (fade_bottom) {
+        ratio *= ratio_bottom;
+    }
+
+    if (fade_left) {
+        ratio *= ratio_left;
+    }
+
+    if (fade_right) {
+        ratio *= ratio_right;
+    }
+
+    cogl_color_out = color * ratio;
+}